package com.supermap.business.cloud.survey;

import com.alibaba.dubbo.config.annotation.Reference;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dataservice.util.Table;
import com.supermap.dubbo.api.cloud.survey.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author aqua
 * @description
 * @date 2018年12月11 下午 3:44
 * @email 1301584033@qq.com
 */
@Controller
@RequestMapping("/cloud/survey")
public class survey {

    @Reference(timeout = 10000000)
    private SurveyService surveyService;

    /**
     * 通过区域查询所有问卷调查
     */
    @GetMapping("/getSurveyCategoryByAreaCode")
    @ResponseBody
    public JSONUtil getSurveyCategoryByAreaCode(String areaCode,Integer userId) {
        return surveyService.getSurveyCategoryByAreaCode(areaCode,userId);
    }

    /**
     * 通过问卷ID查询问卷
     */
    @GetMapping("/getSurveyByCategoryId")
    @ResponseBody
    public JSONUtil getSurveyByCategoryId(Integer id) {
        return surveyService.getSurveyByCategoryId(id);
    }

    /**
     * 上传问题答案
     */
    @PutMapping("/putSurvey")
    @ResponseBody
    public JSONUtil putSurvey(@RequestBody List<Surveyanswer> surveyanswerList) {
        return surveyService.putSurvey(surveyanswerList);
    }

    /***
     * sms问卷列表
     * **/
    @RequestMapping("getSurveyByAreaCode")
    @ResponseBody
    public Table getSurveyByAreaCode(int areaCode, Table table) {
        JSONUtil jsonUtil = surveyService.getSurveyByAreaCodeSMS(areaCode, table);
        table = (Table) jsonUtil.getData();
        table.setMsg(jsonUtil.getMsg());
        table.setCode(jsonUtil.getCode());
        return table;
    }

    /**
     * sms统计第一层
     **/
    @RequestMapping("getCountServeySmsBySendTime")
    @ResponseBody
    public Table getCountServeySmsBySendTime(String startTime, String endTime, Table table, String areaCode) {
        JSONUtil jsonUtil = surveyService.getCountServeySmsBySendTime(startTime, endTime, table, areaCode);
        table = (Table) jsonUtil.getData();
        table.setMsg(jsonUtil.getMsg());
        table.setCode(jsonUtil.getCode());
        return table;
    }

    /***
     * 获取每题选项比例
     * */
    @RequestMapping("getSurveryPre")
    @ResponseBody
    public JSONUtil getSurveryPre(String contentid, String areaCode) {
        return surveyService.getSurveryPre(contentid, areaCode);
    }

    /**
     * 根据问卷id获取回答人员名称
     **/
    @RequestMapping("getAnsSurveyUserNameBySurveyId")
    @ResponseBody
    public Table getAnsSurveyUserNameBySurveyId(Table table, String surveyId, String areaCode) {
        JSONUtil jsonUtil = surveyService.getAnsSurveyUserNameBySurveyId(table, surveyId, areaCode);
        table = (Table) jsonUtil.getData();
        table.setMsg(jsonUtil.getMsg());
        table.setCode(jsonUtil.getCode());
        return table;
    }

    /**
     * 获取问卷回答人对应的答案
     */
    @RequestMapping("getUserOptionByIdAndUserId")
    @ResponseBody
    public JSONUtil getUserOptionByIdAndUserId(Integer id, String userId) {
        return surveyService.getUserOptionByIdAndUserId(id, userId);
    }

    //获取问卷调查名称
    @RequestMapping("getSurveyName")
    @ResponseBody
    public JSONUtil getSurveyName(String areaCode, String userId) {
        return surveyService.getSurveyName(areaCode, userId);
    }

    //获取问卷大题
    @RequestMapping("getSurveyMenuName")
    @ResponseBody
    public JSONUtil getSurveyMenuName(String surveyId) {
        return surveyService.getSurveyMenuName(surveyId);
    }

    /**
     * 删除试卷
     */
    @RequestMapping("delSurvey")
    @ResponseBody
    public JSONUtil delSurvey(String id) {
        return surveyService.delSurvey(id);
    }

    /***
     * 删除大题
     * */
    @RequestMapping("delSurveyMenu")
    @ResponseBody
    public JSONUtil delSurveyMenu(String id) {
        return surveyService.delSurveyMenu(id);
    }

    /**
     * 删除小题
     **/
    @RequestMapping("delSurveyContent")
    @ResponseBody
    public JSONUtil delSurveyContent(String id) {
        return surveyService.delSurveyContent(id);
    }

    /***
     * 获取小题及选项
     * **/
    @RequestMapping("getContentAndOptions")
    @ResponseBody
    public JSONUtil getContentAndOptions(Integer id) {
        return surveyService.getContentAndOptions(id);
    }

    /***
     * 更新问卷
     * **/
    @RequestMapping("updateSurvey")
    @ResponseBody
    public JSONUtil updateSurvey(SurveyDoc surveyDoc) {
        return surveyService.updateSurvey(surveyDoc);
    }

    /***
     * 更新大题
     * **/
    @RequestMapping("updateSurveyMenu")
    @ResponseBody
    public JSONUtil updateSurveyMenu(SurveyMenu surveyMenu) {
        return surveyService.updateSurveyMenu(surveyMenu);
    }

    /***
     * 更新小题和选项
     * **/
    @RequestMapping(value = "updateSurveyContentAndOptions", method = RequestMethod.POST)
    @ResponseBody
    public JSONUtil updateSurveyContentAndOptions(@RequestBody SurveyContent content) {
        return surveyService.updateSurveyContentAndOptions(content);
    }

    /***
     * 新增问卷和区域
     * **/
    @RequestMapping(value = "insertSurvey", method = RequestMethod.POST)
    @ResponseBody
    public JSONUtil insertSurvey(@RequestBody SurveyDoc content) {
        return surveyService.insertSurvey(content);
    }

    /***
     * 新增大题
     * **/
    @RequestMapping(value = "insertSurveyMenu")
    @ResponseBody
    public JSONUtil insertSurveyMenu(SurveyMenu menu) {
        return surveyService.insertSurveyMenu(menu);
    }

    /***
     * 新增小题及选项
     * **/
    @RequestMapping(value = "insertSurveyContentAndOptions", method = RequestMethod.POST)
    @ResponseBody
    public JSONUtil insertSurveyContentAndOptions(@RequestBody SurveyContent content) {
        return surveyService.insertSurveyContentAndOptions(content);
    }
}
